package com.ukao.pad.presenter;

import android.content.Context;

import com.ukao.pad.base.BasePresenter;
import com.ukao.pad.bean.ClothesOperateStatusBean;
import com.ukao.pad.bean.OrderInformationBean;
import com.ukao.pad.bean.ReceiptBean;
import com.ukao.pad.consts.Constant;
import com.ukao.pad.consts.SaveParamets;
import com.ukao.pad.retrofit.ApiCallback;
import com.ukao.pad.utils.Utils;
import com.ukao.pad.view.OrderInformationView;

import java.util.HashMap;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
 * Created by kefu001 on 2018/5/17.
 */

public class OrderInformationPresenter extends BasePresenter<OrderInformationView>{

    public OrderInformationPresenter(OrderInformationView view) {
        super.attachView(view);
    }

    /**
     * 请求订单信息
     */
   public void onRequestOrderInformation(String strCode){
       mvpView.showLoading();
       HashMap mHashMap=new HashMap<String,String>();
       mHashMap.put("scanCode",strCode);
       mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
       addSubscription(super.apiStores.queryOrderInfo(Constant.createParameter(mHashMap)),
               new ApiCallback<OrderInformationBean>() {
                   @Override
                   public void onSuccess(OrderInformationBean model) {
                       if (model.getHttpCode() == 200) {
                           mvpView.requestSuccess(model.getData());
                       }else{
                           mvpView.requestFailure(model.getMsg());
                       }
                   }

                   @Override
                   public void onNoNewWork() {

                   }


                   @Override
                   public void onFinish() {
                       mvpView.hideLoading();
                   }

               });
    }
    /**
     * 打印小票
     * @param orderId
     */
    public void printReceipt(String  orderId) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("orderId",orderId);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.printReceipt(Constant.createParameter(mHashMap)),
                new ApiCallback<ReceiptBean>(){
                    @Override
                    public void onSuccess(ReceiptBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.loadReceiptData(model.getData());
                        }else{
                            mvpView.requestFailure(model.getMsg());
                        }
                    }
                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }
    /**
     *  请求单个衣物操作记录
     * @param context
     * @param proId
     */
    public void requestSingleClothingOperateRecord(Context context, String  proId,String clothesName,String clothesCode) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("proId",proId);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.singleClothingOperateRecord(Constant.createParameter(mHashMap)),
                new ApiCallback<ClothesOperateStatusBean>(){
                    @Override
                    public void onSuccess(ClothesOperateStatusBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.receiveClothesOperateData(model.getData(),clothesName,clothesCode);
                        }else{
                            mvpView.requestFailure(model.getMsg());

                        }
                    }
                    @Override
                    public void onNoNewWork() {
                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }

}
